<?php

namespace App\Http\Service;

use App\Http\Repository\PointGoodsRepository;
use App\Http\Criteria\OrderBySortOrderCriteria;
use App\Http\Criteria\OrderByCreatedAtCriteria;
use App\Http\Criteria\IsActiveCriteria;
use App\Http\Criteria\IDCriteria;



class PointGoodsService extends BaseService
{
    protected $rep;

    public function __construct(PointGoodsRepository $repository)
    {
        $this->rep = $repository;

    }

    public function list()
    {
        $this->rep->pushCriteria(new OrderBySortOrderCriteria());
        $this->rep->pushCriteria(new OrderByCreatedAtCriteria());
        $this->rep->pushCriteria(new IsActiveCriteria());
        return $this->rep->with('goods')->all();
    }

    public function getDetail($id)
    {

        $this->rep->pushCriteria(new IDCriteria($id));

        return $this->rep->with(['goods' => function ($query) {
            $query->with(['images' => function($query) {
                $query->orderBy('sort_order', 'desc')->orderBy('created_at', 'desc');
            }]);
        }])->first();

    }

}
